#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int N=2*1e4+10;

int h[N],ne[N],to[N],idx,w[N];
int t,c,ts,te;
int dist[N];
struct cmp{
	bool operator()(pair<int,int>& p1,pair<int,int>& p2)
	{
		return p1.second>p2.second;
		
	}
};
void add(int x,int y,int z)
{
	ne[idx]=h[x];
	h[x]=idx;
	to[idx]=y;
	w[idx++]=z;
}
void dijkstra(int u)
{
	memset(dist,0x3f3f3f3f,sizeof(dist));
	dist[u]=0;
	priority_queue<pair<int,int>,vector<pair<int,int>>,cmp> q;
	q.push({u,0});
	while(q.size())
	{
		int x=q.top().first;
		q.pop();
		for(int i=h[x];~i;i=ne[i])
		{
			int y=to[i];
			int step=w[i];
			if(dist[y]>dist[x]+step)
			{
				dist[y]=dist[x]+step;
				q.push({y,dist[y]});
			}
		}
	}
	
}
int main()
{
	cin>>t>>c>>ts>>te;
	memset(h,-1,sizeof(h));
	for(int i=0;i<c;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		add(x,y,z);
		add(y,x,z);
	}
	dijkstra(ts);
	cout<<dist[te]<<endl;
	return 0;
}
